<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .top {
      margin-bottom: 20px;
    }
    .tab {
      border: 1px solid #333;
      border-radius: 4px;
      color: #fff;
      background-color: #666;
      padding: 10px;
      cursor: pointer;
    }
    /* 激活的样式 */
    .checked {
      background-color: #56a5f1;
      box-shadow: 5px 5px 5px #333;
    }
  </style>
</head>
<body>
  <div id="app">
    <div class="top">
      <span :class="['tab', {checked: active === 0}]" @click="showItem(0)">评论管理</span>
      <span :class="['tab', {checked: active === 1}]" @click="showItem(1)">发布评论</span>
    </div>
    <form v-show="active === 0">
      <input v-model="name" placeholder="name"/>
      <input v-model="content" placeholder="content"/>
      <button type="button" @click="commit">立即提交</button>
    </form>
    <div v-show="active === 1">
      <div v-for="(item, index) in list" :key="index">
        <p>评论人：{{item.name}}</p>
        <p>评论时间：{{item.time}}</p>
        <p>评论内容：{{item.content}}</p>
      </div>
    </div>
  </div>
  <script src="../vue.js"></script>
  <script>
    let vm = new Vue({
      el: '#app',
      data: {
        name: '',
        content: '',
        list: [],
        // 当前激活的模块
        active: 0
      },
      methods: {
        // 提交评论
        commit() {
          console.log(this.name);
          console.log(this.content);
          this.list.push({
            name: this.name,
            content: this.content,
            time: new Date()
          })
        },
        // 切换模块
        showItem(index) {
          this.active = index
        }
      },
    })
  </script>
</body>
</html>